package demo1;

//    //下转型对象

class Animal{
    String  name;
    int age;
    public Animal(String name,int age){
        this.name = name;
        this.age = age;
    }

    public void eat(){
        System.out.println(name + "吃东西");
    }
}

class Dog extends Animal{
    public Dog(String name,int age){
        super(name,age);
    }


    public void bark() {
        System.out.println(name + "正在汪汪汪....");
    }

    public void eat(){
        System.out.println(name + "吃狗粮");
    }
}


class Bird extends Animal{
    public  Bird(String name,int age){
        super(name,age);
    }

    public void fly() {
        System.out.println(this.name +" 正在飞....");
    }

    public void eat(){
        System.out.println(name + "吃鸟粮");
    }
}


public class Test {
    public static void main(String[] args) {
        Animal animal1 = new Dog("旺财", 10);
        if (animal1 instanceof Dog) {
            Dog dog = (Dog) animal1;
            dog.bark();
        } else {
            System.out.println("animal1没有引用Dog实例");
        }
        System.out.println("===========");
        if (animal1 instanceof Bird) {
            Bird bird = (Bird) animal1;
            bird.fly();
        } else {
            System.out.println("animal1没有引用Bird实例");
        }
    }
}
